package com.example.win.android_banduyujia.peopleactivity.ui.image;

import android.os.Bundle;

import com.example.win.android_banduyujia.peopleactivity.ui.domain.PhotoSelectorDomain;
import com.example.win.android_banduyujia.peopleactivity.ui.model.PhotoModel;
import com.example.win.android_banduyujia.peopleactivity.ui.util.CommonUtils;

import java.util.List;

/**
 * Created by Win on 2015/9/17.
 */
public class PhotoPreviewActivity extends BasePhotoPreviewActivity implements PhotoSelectorActivity.OnLocalReccentListener {

    private PhotoSelectorDomain photoSelectorDomain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        photoSelectorDomain = new PhotoSelectorDomain(getApplicationContext());

        init(getIntent().getExtras());
    }

    private void init(Bundle extras) {
        if(extras == null)
            return;
        if(extras.containsKey("photos")){  // 预览图片
            photos = (List<PhotoModel>) extras.getSerializable("photos");
            current = extras.getInt("position", 0);
            updatePercent();
            bindData();
        }else if(extras.containsKey("album")){  // 点击图片查看
            String albumName = extras.getString("album"); // 相册
            this.current = extras.getInt("position");
            if(!CommonUtils.isNull(albumName) && albumName.equals(PhotoSelectorActivity.RECCENT_PHOTO)){
                photoSelectorDomain.getReccent(this);
            }else{
                photoSelectorDomain.getAlbum(albumName, this);
            }
        }
    }

    @Override
    public void onPhotoLoaded(List<PhotoModel> photos) {
        this.photos = photos;
        updatePercent();
        bindData(); // 更新界面
    }
}
